package com.sfh.controller.task;

import com.jfinal.plugin.activerecord.Db;
import com.sfh.base.Task;
import com.sfh.service.model.MassModel;
import com.sfh.service.model.table.MassTable;
import com.sfh.service.util.SQLHelp;

/***
 * 社团帖子数量
 * 
 * @author DELL
 *
 */
public class TaskMassNoteSize extends Task {
	long massId;
	int size;

	public TaskMassNoteSize(long massId, 	int size) {
		this.massId = massId;
		this.size = size;
	}
	@Override
	public boolean run() {
		MassModel mass = MassModel.MASS.findById(massId);
		if (mass == null) {
			return false;
		}

		final long version = mass.getVersion();
		SQLHelp sql = new SQLHelp(MassTable.Table);
		sql.addWhereEqualTo(MassTable.id, massId);
		sql.addWhereEqualTo(MassTable.version, version);

		sql.updateKeys(MassTable.version, version + 1);
		sql.updateKeys(MassTable.size, mass.getSize() + size);

		int index = Db.update(sql.buildUpdaete());
		return index > 0;
	}

}
